﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using FinPlusAnalytics;
using NUnit.Framework;
using d = FinPlusAnalytics.QLDateParser;

namespace Test_FinPlusAnalytics
{
    class Program
    {
        static void Main(string[] args)
        {
            var TextFixture1 = new TextFixture1();
            TextFixture1.Test1();
        }
    }

    [TestFixture]
    class TextFixture1
    {
        [Test]
        public void Test1()
        {
            var settlementDate = new DateTime(2004, 9, 22);
            var todayDate = d.NextBizDate(settlementDate, "-2D", "ModifiedPreceding", false, "TGT");
            var marketName = "Test1_";

            var market = new Market(marketName, todayDate);
            var indx = new Index(marketName, "EURCurve", "Euribor6M", "Euribor", "6M", "");
            var rates = "EURDepo1W,EURDepo1M,EURFut1,EURFut2,EURFut3,EURFut4,EURFut5,EURFut6,EURFut7,EURFut8,EURSwap3Y,EURSwap5Y,EURSwap10Y,EURSwap15Y";
            
            var depo1 = new DepoRate(marketName, "EURDepo1W", 0.0382, "1W", 2, "Act/360", "ModifiedFollowing", "TGT");
            var depo2 = new DepoRate(marketName, "EURDepo1M", 0.0372, "1M", 2, "Act/360", "ModifiedFollowing", "TGT");

            var immDate = d.NextImmDate(todayDate.AddDays(1));
            var fut1 = new FutRate(marketName, "EURFut1", 96.2875, immDate, 3, "Act/360", "ModifiedFollowing", "TGT");
            var fut2 = new FutRate(marketName, "EURFut2", 96.7875, immDate = d.NextImmDate(immDate.AddDays(1)), 3, "Act/360", "ModifiedFollowing", "TGT");
            var fut3 = new FutRate(marketName, "EURFut3", 96.9875, immDate = d.NextImmDate(immDate.AddDays(1)), 3, "Act/360", "ModifiedFollowing", "TGT");
            var fut4 = new FutRate(marketName, "EURFut4", 96.6875, immDate = d.NextImmDate(immDate.AddDays(1)), 3, "Act/360", "ModifiedFollowing", "TGT");
            var fut5 = new FutRate(marketName, "EURFut5", 96.4875, immDate = d.NextImmDate(immDate.AddDays(1)), 3, "Act/360", "ModifiedFollowing", "TGT");
            var fut6 = new FutRate(marketName, "EURFut6", 96.3875, immDate = d.NextImmDate(immDate.AddDays(1)), 3, "Act/360", "ModifiedFollowing", "TGT");
            var fut7 = new FutRate(marketName, "EURFut7", 96.2875, immDate = d.NextImmDate(immDate.AddDays(1)), 3, "Act/360", "ModifiedFollowing", "TGT");
            var fut8 = new FutRate(marketName, "EURFut8", 96.0875, immDate = d.NextImmDate(immDate.AddDays(1)), 3, "Act/360", "ModifiedFollowing", "TGT");
            //build swap rates
            var swap1 = new SwapRate(marketName, "EURSwap3Y", 0.0398, 0, "3Y", 3, 0, "Euribor6M", "Annual", "Euro30/360", "Unadjusted", "TGT");
            var swap2 = new SwapRate(marketName, "EURSwap5Y", 0.0443, 0, "5Y", 3, 0, "Euribor6M", "Annual", "Euro30/360", "Unadjusted", "TGT");
            var swap3 = new SwapRate(marketName, "EURSwap10Y", 0.05165, 0, "10Y", 3, 0, "Euribor6M", "Annual", "Euro30/360", "Unadjusted", "TGT");
            var swap4 = new SwapRate(marketName, "EURSwap15Y", 0.055175, 0, "15Y", 3, 0, "Euribor6M", "Annual", "Euro30/360", "Unadjusted", "TGT");

            var curve1 = new YieldCurve(marketName, "EURCurve", "EURCurve", settlementDate, rates, "Act/Act:ISDA", "TGT");

            //create basis trade and value
		    //std::string spot5YearBasisSwap1 = qlProxy.BasisSwap("Mkt_", "Cache1_","spot5YearBasisSwap1", 1000000.0, settlementDate.serialNumber(), (settlementDate + 5*Years).serialNumber(),"Payer", "EURCurve", "Euribor6M", 0.0, "Semiannual",  "ModifiedFollowing", "Act/360", "EURCurve", "Euribor6M", 0.0, "Annual",  "Unadjusted", "Euro30/360", "TGT");
		    //std::string spot5YearBasisSwap2 = qlProxy.BasisSwap("Mkt_", "Cache1_","spot5YearBasisSwap2", 1000000.0, settlementDate.serialNumber(), (settlementDate + 5*Years).serialNumber(),"Receiver",	"EURCurve", "Euribor6M", 0.0, "Annual",  "Unadjusted", "Euro30/360","EURCurve", "Euribor6M", 0.0, "Semiannual",  "ModifiedFollowing", "Act/360","TGT");
            //var spot5YearSwap1 = new VanillaSwap(marketName, "Cache1_", "spot5YearSwap1", "EURCurve", -1000000.0, settlementDate, (settlementDate + 5 * Years).serialNumber(), 0.04, "Receiver", "Euribor6M", 0.0, "Annual", "Semiannual", "Unadjusted", "ModifiedFollowing", "Euro30/360", "Act/360", "TGT");
		    //std::string spot5YearSwap2 = qlProxy.VanillaSwap("Mkt_", "Cache1_","spot5YearSwap2", "EURCurve", 1000000.0, settlementDate.serialNumber(), (settlementDate + 5*Years).serialNumber(), 0.04,"Receiver", "Euribor6M", 0.0, "Annual", "Semiannual", "Unadjusted", "ModifiedFollowing", "Euro30/360", "Act/360","TGT");
		    //std::string allTrades1 = qlProxy.MarketValueTrades("Mkt_", "Cache1_", "NPV,FloatingLegNPV,FloatingLeg2NPV");


            //Assert.AreEqual(q.Functions.Count, 2);
            //Console.WriteLine("TextFixture1.Test1");
        }
    }
}
